﻿using JzSport.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JzSport.Api
{
    class ChangePasswordAction : AuthPostAction<Params.ChangePasswordParams,
        Results.ChangePasswordResult>
    {
        protected override ActionResult<Results.ChangePasswordResult> OnExecute(ActionContext context, SysParameters sysParameters,
            Params.ChangePasswordParams opParams)
        {
            ServiceResult<Account> serviceResult = new AccountService().ChangePassword(context.AccountId,
                opParams.OldPassword,
                opParams.Password);

            Results.ChangePasswordResult actionResult = new Results.ChangePasswordResult();

            if (serviceResult.ErrorCode == ErrorCode.NoError)
            {

                return new ActionResult<Results.ChangePasswordResult>(true, serviceResult.ErrorCode,
                    ErrorCode.ToString(serviceResult.ErrorCode), actionResult);
            }
            return new ActionResult<Results.ChangePasswordResult>(false, serviceResult.ErrorCode,
                    ErrorCode.ToString(serviceResult.ErrorCode), actionResult);
        }
    }
}
